﻿using System;
using System.ComponentModel;
using System.Globalization;

namespace TeamDeployer.TeamFoundation.Build.Workflow.CustomTypes
{
    internal class DeploySpecConverter : ExpandableObjectConverter
    {
        // Methods
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            return ((destinationType == typeof(string)) ||
                    base.CanConvertTo(context, destinationType));
        }

        public override object ConvertTo(ITypeDescriptorContext context,
                                         CultureInfo culture,
                                         object value,
                                         Type destinationType)
        {
            DeploySpec spec = value as DeploySpec;
            if ((destinationType != typeof(string)) || (spec == null))
            {
                return base.ConvertTo(context, culture, value, destinationType);
            }
            return spec.Name;
        }
    }
}